//
//  YFStatusList.swift
//  微博
//
//  Created by 余仿 on 16/4/11.
//  Copyright © 2016年 YF. All rights reserved.
//

import UIKit

class YFStatusList: NSObject {


    //文本
    var text:String?

    //来源
    var source:String?

    //发布时间
    var created_at:String?

    //用户
    var user:YFUser?

    //id
    var id:Int64 = 0


//    reposts_count 	int 	转发数

    var reposts_count:Int = 0
//    comments_count 	int 	评论数
    var comments_count:Int = 0
//    attitudes_count 	int 	表态数
    var attitudes_count:Int = 0

    //转发微博
    var retweeted_status:YFStatusList?

    //图片相关字段
    var pic_urls:[YFPicture]?

    //字典转模型
    init(dict:[String:AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }

    //描述模型
    override var description: String {
        let keys = ["text","created_at","id"]

        let dict = self.dictionaryWithValuesForKeys(keys)
        
        return dict.description

    }

    override func setValue(value: AnyObject?, forUndefinedKey key: String) {

    }


    override func setValue(value: AnyObject?, forKey key: String) {

        if key == "user"{

            user = YFUser(dict: value as! [String:AnyObject])
            return;
        }

        if key == "retweeted_status"{

            retweeted_status = YFStatusList(dict: value as! [String:AnyObject])

            return
        }

        var tempArray = [YFPicture]()
        if key == "pic_urls"{

            //value是字典数组,需要遍历取出字典,字典转模型
            let picArray = value as! [[String:String]]

            for dict in picArray{

                let pictureModel = YFPicture(dict:dict)

                tempArray.append(pictureModel)
            }

            pic_urls = tempArray

            return
        }

        super.setValue(value, forKey: key)
    }


}
